<template>

    <div class="content manifest-list">
        <div class="content-top">
            <Button class="icon-btn" type="primary" @click="add">新增</Button>
            <Button class="icon-btn" type="primary" @click="apply">申报</Button>
            <Button class="icon-btn" @click="del">删除</Button>
            <!-- <Button class="icon-btn" type="primary" @click="importHandle">导入</Button> -->
            <SearchExpand class="search-collapse-small">
                <Form v-model="params" class="clearfix" :label-width="88">
                    <Row>
                        <iCol :span="3" class="search-label" >预录入统一编号</iCol>
                        <iCol :span="4">
                            <Input v-model="params.seqNo" placeholder=""/>
                        </iCol>
                        <iCol :span="3" class="search-label" >加工贸易手册编号</iCol>
                        <iCol :span="4">
                            <Input v-model="params.emlNo" placeholder=""/>
                        </iCol>
                        <iCol :span="4">
                            <Button class="icon-btn" type="primary" @click="search">
                                查询
                            </Button>
                        </iCol>
                    </Row>
                </Form>
            </SearchExpand>
        </div>
        <div class="content-body">
            <Table @on-selection-change="changeSelected" :data="list" :columns="columns" border align="center">

                <template slot-scope="{ row }" slot="status">
                    <div>{{ row.status==1?'暂存':'申报' }}</div>
                </template>
                <template slot-scope="{ row }" slot="action">
                    <a @click="view(row)">查看</a>&nbsp;
                    <a @click="applyOne(row.emlId)">申报</a>&nbsp;
                </template>

            </Table>
            <Pagination
                :pageSize.sync="params.pageSize"
                :current.sync="params.pageNum"
                :total="total"
                @change="queryList"
            />
        </div>

    </div>
</template>
<script>
import { queryEmlList, delEml, declareEml } from '@/api/trade'
import { downloadDoc } from '@/api/fileManage'
import SearchExpand from '_c/search-expand'
export default {
    inject: ['nextPageReload'],
    components: {
        SearchExpand
    },
    data () {
        return {
            trainingId: '',
            selecetd: [],
            total: 0,
            roleType: '',
            schoolList: [],
            params: {
                seqNo: '', // 预录入
                emlNo: '', // 加工贸易手册编号
                pageNum: 1,
                pageSize: 10,
                type: 1
            },
            list: [],
            columns: Object.freeze([
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                { title: '预录入统一编号', key: 'seqNo', align: 'center', width: 150 },
                { title: '加工贸易手册编号', key: 'emlNo', align: 'center', width: 130 },
                { title: '数据状态', slot: 'status', align: 'center' },
                { title: '经营单位代码', key: 'bizopEtpsno', align: 'center' },
                { title: '加工单位代码', key: 'rcvgdEtpsno', align: 'center', width: 80 },
                { title: '加工单个名称', key: 'rcvgdEtpsNm', align: 'center', width: 80 },
                { title: '申报类型', key: 'dclTypecd', align: 'center', width: 80 },
                { title: '有效期', key: 'validDate', align: 'center', width: 80 },
                { title: '申报日期', key: 'dclTime', align: 'center' },
                { title: '操作', slot: 'action', align: 'center', width: 100 }

            ])
        }
    },
    mounted () {
        this.queryList()
        // this.getSchoolList()
        // this.getRoleType()
        console.log(this.$route)
        this.trainingId = this.$route.params.trainingId
    },
    methods: {
        changeSelected (data) {
            this.selecetd = data
        },
        clearSearch () {
            this.certNo = ''
            this.type = ''
            this.companyName = ''
            this.invNo = ''
            this.applyStartTime = ''
            this.applyEndTime = ''
            this.createStartTime = ''
            this.createEndTime = ''
            this.queryList()
        },
        search () {
            this.params.pageNum = 1
            this.queryList()
        },
        queryList () {
            queryEmlList(this.params).then(res => {
                if (res.data.code === '0000') {
                    this.list = res.data.data.list
                    this.total = res.data.data.total
                }
            })
        },
        view (row) {
            this.nextPageReload()
            this.$router.push({
                name: 'tradeInfo',
                query: {
                    emlId: row.emlId
                }
            })
        },
        add () {
            this.nextPageReload()
            this.$router.push({
                name: 'tradeInfo'
            })
        },
        handleEdit (id) {
            this.nextPageReload()
            this.$router.push({
                name: 'normalCert',
                query: {
                    type: type
                }
            })
        },
        apply () {
            if (this.selecetd.length > 0) {
                let idArr = this.selecetd.map(item => {
                    return item.emlId
                })
                let ids = idArr.join(',')
                declareEml(ids).then(res => {
                    if (res.data.code === '0000') {
                        this.$Message.success('申报成功')
                        this.params.pageNum = 1
                        this.queryList()
                    } else {
                        this.$Message.error(res.data.msg)
                    }
                })
            } else {
                this.$Message.error('请勾选')
            }
        },
        applyOne (id) {
            declareEml(id).then(res => {
                if (res.data.code === '0000') {
                    this.$Message.success('申报成功')
                    this.params.pageNum = 1
                    this.queryList()
                } else {
                    this.$Message.error(res.data.msg)
                }
            })
        },
        del () {
            if (this.selecetd.length > 0) {
                this.$Modal.confirm({
                    title: '提示',
                    content: '确认是否删除？',
                    onOk: () => {
                        let idArr = this.selecetd.map(item => {
                            return item.emlId
                        })
                        let ids = idArr.join(',')
                        delEml(ids).then(res => {
                            if (res.data.code === '0000') {
                                this.$Message.success('删除成功')
                                this.params.pageNum = 1
                                this.queryList()
                            } else {
                                this.$Message.error(res.data.msg)
                            }
                        })
                    }
                })
            } else {
                this.$Message.error('请勾选')
            }
        },
        delO (id) {
            this.$Modal.confirm({
                title: '提示',
                content: '确认是否删除？',
                onOk: () => {
                    delEml(id).then(res => {
                        if (res.data.code === '0000') {
                            this.$Message.success('删除成功')
                            this.params.pageNum = 1
                            this.queryList()
                        } else {
                            this.$Message.error(res.data.msg)
                        }
                    })
                }
            })
        },
        handleDownload (id) {
            downloadDoc(id, '/case/download')
        }
    }
}
</script>
